<template>
  <div class="info-container">
    <el-card style="height: 100%">
      <div class="top">
        <span
          v-for="(item, index) in DutyTypeDrop"
          :key="index"
          :class="['top-son', { lower: index === indexa }]"
          :style="index === indexa ? 'color:#16171C' : 'color:#c1c1c1'"
          @click="TopMenu(item, index)"
          >{{ item.arrangetype }}</span
        >
      </div>
      <search-tool @onSearch="handleSearch"></search-tool>
      <el-table
        v-loading="loading"
        :data="tableData"
        style="width: 100%; position: relative"
        height="75%"
        @selection-change="handleSelectionChange"
      >
        <el-table-column label="序号" type="index" />
        <el-table-column prop="arrangetype" label="值班类型"> </el-table-column>
        <el-table-column prop="userName" label="当班人员	"> </el-table-column>
        <el-table-column prop="monitorName" label="值班班长"> </el-table-column>
        <el-table-column prop="arrangeDate" label="值班日期"> </el-table-column>
        <el-table-column prop="startTime" label="值班开始时间">
        </el-table-column>
        <el-table-column prop="endTime" label="值班结束时间"> </el-table-column>
        <el-table-column prop="remark" label="值班说明"> </el-table-column>
        <el-table-column label="操作">
          <template #default="{ row }">
            <div class="action-row">
              <button
                :class="
                  !row.endTime && !row.fileUrl === true ? 'Regbtn' : 'DeRegbtn'
                "
                :disabled="!row.endTime === true ? false : true"
                @click="handleRegist(row)"
              >
                登记
              </button>
            </div>
          </template>
        </el-table-column>
      </el-table>

      <el-pagination
        class="pagination"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="page"
        :page-sizes="[5, 10, 20]"
        :page-size="size"
        layout="prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </el-card>
    <register-diaog
      :title="dialogRegTitle"
      :rowData="curRowDataReg"
      v-model:visible="visibleDialogRef"
      @onReload="reloadPageReg"
    ></register-diaog>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import SearchTool from './components/SearchTool/index.vue'
import registerDiaog from './components/RegisterDialog/index'
import { ElMessageBox } from 'element-plus'
import { RecordsDutyList, ComDutyTypeDrop } from '@/api/dutyManagement'
import { message } from '@/utils/message'
//数据相关
const tableData = ref([])
const total = ref(0)
const page = ref(1)
const size = ref(8)
const params = ref({
  arrangeType: '',
  endDate: '',
  startDate: '',
  userName: ''
})
const indexa = ref(0)
const loading = ref(false)
const visibleDialogRef = ref(false)
const curRowDataReg = ref({})
const dialogRegTitle = ref('')
const btnIs = ref(false)
const DutyTypeDrop = ref([]) //监控类型下拉列表
// 获取数据的方法
const getListData = async (params) => {
  loading.value = true
  const result = await RecordsDutyList(params, page.value, size.value)
  loading.value = false
  tableData.value = result.rows
  total.value = result.total
}
onMounted(() => {
  GetComDutyTypeDro() //值班类型
})

// 顶部菜单点击事件
const TopMenu = (item, index) => {
  indexa.value = index
  params.value.arrangeType = DutyTypeDrop.value[index].arrangetype
  getListData(params.value)
}

const reloadPageReg = () => {
  getListData(params.value)
  if (visibleDialogRef.value) {
    visibleDialogRef.value = false
  }
}

reloadPageReg()
//获取值班类型下拉列表
const GetComDutyTypeDro = () => {
  ComDutyTypeDrop().then((res) => {
    let data = res
    DutyTypeDrop.value = [...data]
  })
}
// 查询条件相关
const handleSearch = (paramsData) => {
  console.log(paramsData)
  params.value = paramsData
  let obj = {
    userName: paramsData.userName,
    startTime: paramsData.time[0],
    endTime: paramsData.time[1]
  }
  getListData(obj)
}
// 分页相关
/**
 * size 改变触发
 */
const handleSizeChange = (currentSize) => {
  size.value = currentSize
  getListData(params.value)
}

/**
 * 页码改变触发
 */
const handleCurrentChange = (currentPage) => {
  page.value = currentPage
  getListData(params.value)
}
const handleRegist = (row) => {
  dialogRegTitle.value = '值班登记'
  curRowDataReg.value = row
  visibleDialogRef.value = true
}
</script>

<style lang="scss" scoped>
.top {
  width: 100%;
  height: 51px;
  line-height: 47px;
  padding-left: 24px;
  padding-right: 24px;
  border-bottom: 1px solid #e7e7e7;
  color: #b7b7b7;
  font-size: 16px;
  .top-son {
    width: 70px;
    height: 47px;
    margin-right: 20px;
    margin-top: -60px;
    display: inline-table;
    white-space: nowrap;
    cursor: pointer;
  }
}
.lower {
  border-bottom: 3px solid #1d6ae6 !important;
}
.info-container {
  width: 100%;
  height: 100%;
  .action-row {
    display: flex;
    .Regbtn {
      width: 53px;
      height: 30px;
      background: #afffe8;
      border-radius: 6px 6px 6px 6px;
      opacity: 1;
      border: 1px solid #00c38b;
      font-size: 14px;
      color: #00c38b;
      &:hover {
        cursor: pointer;
      }
    }
    .DeRegbtn {
      width: 53px;
      height: 30px;
      background: #f1f1f1;
      border-radius: 6px 6px 6px 6px;
      opacity: 1;
      border: 1px solid #aaaaaa;
      font-size: 14px;
      color: #b5b5b5;
    }
  }
  .pagination {
    width: 100%;
    height: 32px;
    margin-top: 20px;
    display: flex;
    align-items: center;
    justify-content: end;
  }
}
</style>
